#include <iostream>
using namespace std;

class Queue
{
public:
	Queue(int size = 10)
	{
		_pQue = new int[size];
		_front = _rear = 0;
		_size = size;
	}
	Queue(const Queue& src)
	{
		_front = src._front;
		_rear = src._rear;
		_size = src._size;
		_pQue = new int[_size];
		for (int i = src._front; i != _rear;i=(i+1)%_size)
		{
			_pQue[i] = src._pQue[i];
		}
	}
	Queue& operator=(const Queue&src)
	{
		if(this==&src)
		{
			return *this;
		}
		delete[] _pQue;
		_front = src._front;
		_rear = src._rear;
		_size = src._size;
		_pQue = new int[_size];
		for (int i = src._front; i != _rear; i = (i + 1) % _size)
		{
			_pQue[i] = src._pQue[i];
		}
	}
	~Queue()
	{
		delete[] _pQue;
		_pQue = nullptr;
	}
	void push(int val)
	{
		if (full())
			resize();
		_pQue[_rear++] = val;
		_rear = _rear % _size;
	}
	void pop()
	{
		if (empty())
			return;
		_front = (_front + 1) % _size;
	}
	int front()
	{
		return _pQue[_front];
	}
	bool full()
	{
		return (_rear + 1) % _size == _front;
	}
	bool empty()
	{
		return _rear == _front;
	}

private:
	int *_pQue; // 申请队列的空间数组
	int _front; // 指示队头的位置
	int _rear;	// 指示队尾的位置
	int _size;

	void resize()
	{
		int *temp = new int[_size * 2];
		int index = 0;
		for (int i = _front; i != _rear; i = (i + 1) % _size)
		{
			temp[index++] = _pQue[i];
		}
		delete[] _pQue;
		_pQue = temp;
		_front = 0;
		_rear = index;
		_size = 2 * _size;
	}
};
int main()
{
	Queue q;
	for (int i = 0; i < 30; i++)
	{
		q.push(i);
	}
	while (!q.empty())
	{
		cout << q.front() << " ";
		q.pop();
	}

	Queue m = q;
	m = q;
	return 0;
}